package com.ktgj.flight.common.huaxia;

import com.ktgj.flight.common.pay._Yeepay;
import com.ktgj.flight.domain.InterfaceEntity.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class Test_G5 {
    public static void main(String[] args) {

        //NAY|PVG|2017-12-18 13:50:00|KN5981|T|39|0|T|500|500|620|7|False|0|120|False|2017-12-18 16:05:00||T1

        //订单号:JS202110131655431015
        //票号:

        _G5 g5 = new _G5();

        UUID uuid = UUID.randomUUID();
//
//        //查询机票
        /*MoFlightSearchRequest moFlightSearchRequest = new MoFlightSearchRequest();
        //出发城市
        moFlightSearchRequest.GoSearchWhere.OrgAirport = "HAK";//AKU-PVG  G533L5S    11.23
        //到达城市
        moFlightSearchRequest.GoSearchWhere.DstAirport = "NGB";
        //查询日期
        moFlightSearchRequest.GoSearchWhere.DepDate = "2022-04-01";
        //航司二字码
        moFlightSearchRequest.GoSearchWhere.carrier = "G5";
        //行程类型
        moFlightSearchRequest.TripType = 1;
        MoFlightSearchResponse moFlightSearchResponse = g5._FlightSearch(moFlightSearchRequest);*/


        //创建订单
        MoCreateOrderRequest moCreateOrderRequest = new MoCreateOrderRequest();

        moCreateOrderRequest.OrderID = uuid.toString();

        moCreateOrderRequest.PolicyID = "2";

        MoSegment moSegment = new MoSegment();
        moSegment.FlightNo = "G53109S";
        moSegment.OrgAirport = "AKU";
        moSegment.DstAirport = "PVG";//11.23
        moSegment.DepDate = convertToDate("2022-04-23 19:50:00","yyyy-MM-dd HH:mm:ss");
        moSegment.ArrDate = convertToDate("2022-04-24 11:30:00","yyyy-MM-dd HH:mm:ss");
        moSegment.Cabin = "W";
        moSegment.Airline = "G5";

        moCreateOrderRequest.ListGoSegment.add(moSegment);

        MoPassenger moPassenger = new MoPassenger();

        moPassenger.TicketAmount = new BigDecimal(1135.00);
        moPassenger.AgencyFee = new BigDecimal(15.00);
        moPassenger.AirportTax = new BigDecimal(100.00);
        moPassenger.FuelTax = new BigDecimal(40);

        moPassenger.PassengerName = "测试刘健";
        moPassenger.PassengerType = 1;
        moPassenger.IDType = 1;
        moPassenger.IDNO = "140728199808160055";
        moPassenger.PassengerMobile = "17635156215";
        moPassenger.Sex = true;
        moPassenger.Birthday = convertToDate("1998-08-16","yyyy-MM-dd");

        moCreateOrderRequest.ListMoPassenger.add(moPassenger);

        MoContacts contacts = new MoContacts();
        contacts.ContactName = "刘健";
        contacts.ContactPreNum = "86";
        contacts.ContactMobile = "17710180782";
        contacts.Address = "北京";

        moCreateOrderRequest.Contacts = contacts;

        moCreateOrderRequest.IsNeedPost = true;

        moCreateOrderRequest.TripType = 1;

        MoCreateOrderResponse moCreateOrderResponse = g5._OrderCreate(moCreateOrderRequest);


        //查询订单详情
        MoQueryOrderRequest moQueryOrderRequest = new MoQueryOrderRequest();

        moQueryOrderRequest.OrderID = "JS202110261342121010";

        MoQueryOrderResponse moQueryOrderResponse = g5._QueryOrderInfo(moQueryOrderRequest);

        //取消订单
        MoCancelOrderRequest moCancelOrderRequest = new MoCancelOrderRequest();

        MoOrderItem moOrderItem = new MoOrderItem();
        moOrderItem.OrderID = "JS202110251645491004";

        moCancelOrderRequest.ListOrderItem = moOrderItem;

        MoCancelOrderResponse moCancelOrderResponse = g5._CancelOrder(moCancelOrderRequest);


        //订单支付
        MoYeePayRequest moYeePayRequest = new MoYeePayRequest();
        _Yeepay yeepay = new _Yeepay();

        moYeePayRequest.ExternalNo = "JS202110261342121010";
        moYeePayRequest.OrderID = "JS202110261342121010";
        moYeePayRequest.PayAmount = new BigDecimal(1665.00);

        MoOrderPayResponse moOrderPayResponse1 = yeepay._OrderPayment(moYeePayRequest);


        //出票接口
        MoOrderPayRequest moOrderPayRequest = new MoOrderPayRequest();

        moOrderPayRequest.OrderID = "JS202110261342121010";
        moOrderPayRequest.PayId = "YP2110261344462853319";

        MoOrderPayResponse moOrderPayResponse = g5._OrderPay(moOrderPayRequest);


//        //退票手续费
//        MoOrderRefundCaltRequest moOrderRefundCaltRequest = new MoOrderRefundCaltRequest();
//
//        moOrderRefundCaltRequest.RepurchaseTicket = "9872014971794";
//        moOrderRefundCaltRequest.OutOrderID = "JS202110261342121010";
//        moOrderRefundCaltRequest.RefundType = 1;
//
//        MoOrderRefundCaltResponse moOrderRefundCaltResponse = g5._OrderRefundCalt(moOrderRefundCaltRequest, false);


//        //申请退票
//        MoOrderRefundRequest moOrderRefundRequest = new MoOrderRefundRequest();
//
//        MoPassenger moPassenger = new MoPassenger();
//        moPassenger.TicketNo = "9872014971794";
//
//        moOrderRefundRequest.ListMoPassenger.add(moPassenger);
//
//        moOrderRefundRequest.OrderID = "JS202110261342121010";
//        moOrderRefundRequest.RepurchaseTicket = "9872014971794";
//        moOrderRefundRequest.RefundType = 1;
//
//        MoOrderRefundResponse moOrderRefundResponse = g5._OrderRefund(moOrderRefundRequest);
    }

    public static Date convertToDate(String str,String pattern){
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        Date date = null;
        if(str != null){
            try {
                date = format.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return date;
    }
}
